<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
	<form action="">
		用户名：<input id="username" type="text" name="username">
		<input type="submit" value="注册">
		<span  class="notice" style="color: red"></span>
	</form>
	<script>
		
		
		$('#username').blur(function(event) {
			username = $(this).val();

			console.log(username);

			$.ajax({
				url: './checkreg.php',
				type: 'POST',
				dataType: 'json',
				data: {id:90,username:username},
			})
			.done(function(res) {
				console.log(res);
				if(res.code==1){
					$('.notice').html(res.msg)
				}else{
					$('.notice').empty();
				}
			})
			.fail(function() {
				console.log("error");
			})
			



		});



	</script>
</body>
</html>